package com.ews.onlineexchange.controller;

import java.util.ArrayList;
import java.util.List;

import javax.enterprise.inject.Model;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.apache.commons.lang3.StringUtils;

import com.ews.onlineexchange.model.ServiceBuyer;
import com.ews.onlineexchange.model.ServiceSupplier;
import com.ews.onlineexchange.service.EntityQuery;

@Model
public class ServiceBuyerListForRest extends EntityQuery<ServiceBuyer> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String buyerName;
	
	public ServiceBuyerListForRest() {
		setOrder("createDate desc");
		setMaxResults(MAX_RESULTS_NORMAL);
	}
	@Override
	protected List<Predicate> getRestrictions(CriteriaBuilder cb, Root<ServiceBuyer> entity) {
		List<Predicate> restrictions = new ArrayList<Predicate>();
		if (!StringUtils.isBlank(buyerName))
			restrictions.add(cb.like(entity.get("cnname"), getStringRestriction(buyerName)));
		restrictions.add(cb.isTrue(entity.<Boolean>get("auditted")));
		return restrictions;
	}
	public String getBuyerName() {
		return buyerName;
	}
	public void setBuyerName(String buyerName) {
		this.buyerName = buyerName;
	}
	
	
}
